package com.may.wlrj.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.may.wlrj.entity.OrganizationEntity;
import com.may.wlrj.entity.UserEntity;
import com.may.wlrj.services.OrganizationService;

@Controller
public class OrganizationController {
	private OrganizationService orgService;
    @Autowired
    public void setOrgService(OrganizationService orgService){
        this.orgService = orgService;
    }
	
	@RequestMapping(value="/orgtree",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String orgTree(HttpSession session) throws IOException{

		System.out.println("---------------------->>>>orgtree");
		return orgService.InitOrgTree(session);
		
	}
	
	@RequestMapping(value="/orgfortreetable",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String orgfortreetable(HttpSession session) throws IOException{

		System.out.println("---------------------->>>>orgtree");
		return orgService.OrgTreeForTreeTable(session);
		
	}
	
	@RequestMapping(value="/orgadd",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody DeferredResult<String> orgAdd(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{    
		DeferredResult<String> deferredResult = new DeferredResult<String>();
		orgService._addOrganization(deferredResult,objnode,request, session);
		return deferredResult;
	}
	
	@RequestMapping(value="/orgedit",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody DeferredResult<String> orgEdit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{  	
		DeferredResult<String> deferredResult = new DeferredResult<String>();
		orgService._editOrganization(deferredResult,objnode,request, session);	
		return deferredResult;
	}
	
	@RequestMapping(value="/orgdelete",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody DeferredResult<String> orgDelete(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	    
		DeferredResult<String> deferredResult = new DeferredResult<String>();
		orgService._deleteOrganization(deferredResult,objnode,request, session);	
		return deferredResult;
	}
}
